package swingxrcp.framework.client.action;

import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;

/**
 * 基于HttpClient的传输器实现
 *
 * @author liangfei
 * @since 2008-10-26
 */
public class HttpClientTransporter extends HttpTransporter {

	private final HttpClient client;

	public HttpClientTransporter(String host, int port, String context,
			String suffix) {
		super(host, port, context, suffix);
		client = new DefaultHttpClient();
	}

	@Override
	protected InputStream doTransport(String url, Serializable object) throws IOException {
		HttpPost request = new HttpPost(url);
		request.setEntity(new SerializeEntity(serializer, object));
		HttpResponse response = client.execute(request);
		HttpEntity entity = response.getEntity();
		return entity.getContent();
	}

}
